﻿using SoldiHive.Core.Adapters;
using SoldiHive.Core.Persistence;
using SoldiHive.Model;
using System;
using System.Linq;
using System.Collections.Generic;

namespace SoldiHive.Core.Crawlers
{
	public class EarningsStatementsCrawler : IEarningsStatementsCrawler
	{
		private ICompanyRepository companyRepository;
		private IEarningsStatementsAdapter earningsStatementsAdapter;

		public EarningsStatementsCrawler(ICompanyRepository companyRepository, IEarningsStatementsAdapter earningsStatementsAdapter)
		{
			this.companyRepository = companyRepository;
			this.earningsStatementsAdapter = earningsStatementsAdapter;
		}

		public IList<EarningsStatement> GetEarningsStatements(DateTime date)
		{
			var earningsStatements = this.earningsStatementsAdapter.GetEarningsStatements(date)
				.Where(earningsStatement => earningsStatement.Company != null)
				.ToList();

			return earningsStatements;
		}

		public IList<EarningsStatement> GetEarningsStatements(IList<DateTime> dates)
		{
			var earningStatements = new List<EarningsStatement>();
			foreach (var date in dates)
			{
				earningStatements.AddRange(this.GetEarningsStatements(date));
			}

			return earningStatements;
		}

		public IList<EarningsStatement> GetPastEarningsStatements(Company company)
		{
			return this.earningsStatementsAdapter.GetPastEarningsStatements(company);
		}


		public EarningsStatement GetEarningsStatement(Company company)
		{
			return this.earningsStatementsAdapter.GetEarningsStatement(company);
		}
	}
}
